import user from '@/api/user'

export default {
    state: {
        userId: 0,
        gender: "",
        age: 0,
        avatar: "",
        address: "",
        isCamera: 0,
        goodNum: 0,
        collectNum: 0,
        gmtCreate: "",
        username: "",
        orderNumber: 0,
        isUseful: 0,
        isSuper: 0,
        is_login: false,
        verifyCode: '',
        signature: '',
        nickname: '',
        followNum: 0,
        fanNum: 0,
        joinNum: 0,
        phone: '',
        email: '',
        identify: '',
    },
    getters: {
    },
    mutations: {
        setInfo(state, user) {
            state.username = user.username;
            state.signature = user.signature;
            state.gender = user.gender;
            state.address = user.address;   
            state.nickname = user.nickname;   
        },
        setCamerist(state, camerist) {
            state.phone = camerist.phone;
            state.email = camerist.email;
            state.identify = camerist.avatar;
        },
        setAvatar(state, avatar) {
            state.avatar = avatar;
        },
        setIsCamerist(state) {
            state.isCamera = 1;
        },
        setOrderAdd(state) {
            state.orderNumber = state.orderNumber + 1;
        },
        setJoinAdd(state) {
            state.joinNum = state.joinNum + 1;
        },
        setGoodNumAdd(state) {
            state.goodNum = state.goodNum + 1;
        },
        setCollectNumAdd(state) {
            state.collectNum = state.collectNum + 1;
        },
        setGoodNumSubtract(state) {
            state.goodNum = state.goodNum - 1;
        },
        setCollectNumSubtract(state) {
            state.collectNum = state.collectNum - 1;
        },
        setFollowNumAdd(state) {
            state.followNum = state.followNum + 1;
        },
        setFanNumAdd(state, user) {
            state.fanNum = user.fanNum + 1;
        },
        setFollowNumSubtract(state) {
            state.followNum = state.followNum - 1;
        },
        setFanNumSubtract(state, user) {
            state.fanNum = user.fanNum - 1;
        },
        setVerifyCode(state, value) {
            state.verifyCode = value
        },
        updateUser(state, user){
            state.userId = user.userId;
            state.gender = user.gender;
            state.age = user.age;
            state.avatar = user.avatar;
            state.address = user.address;
            state.isCamera = user.isCamera;
            state.goodNum = user.goodNum;
            state.collectNum = user.collectNum;
            state.gmtCreate = user.gmtCreate;
            state.username = user.username;
            state.orderNumber = user.orderNumber;
            state.isUseful = user.isUseful;
            state.isSuper = user.isSuper;
            state.signature = user.signature;
            state.nickname = user.nickname;
            state.followNum = user.followNum;
            state.fanNum = user.fanNum;
            state.joinNum = user.joinNum;
        },
        updateLoginStatus(state, login) {
            state.is_login = login
        },
        logout(state) {
            state.userId = 0;
            state.gender = '';
            state.age = 0;
            state.avatar = "";
            state.address = "";
            state.isCamera = 0;
            state.goodNum = 0;
            state.collectNum = 0;
            state.gmtCreate = "";
            state.username = "";
            state.orderNumber = 0;
            state.isUseful = 0;
            state.isSuperUser = 0;
            state.is_login = false;
            state.signature = '';
            state.fanNum = 0;
            state.followNum = 0;
            state.joinNum = 0;
        },
    },
    actions: {
        toLogin(context, data) {
            user.login(data).then( res => {
                context.commit("updateUser", res.data.user)
            })
        }
    },
    modules: {

    }
}